package android.slc.module.sys.ui.dict.data

import android.slc.base.api.slc.callback.po.SlcEntity
import android.slc.fast.vd.list.BaseListPageVmSubByFx
import android.slc.appdb.core.DbEntityMaster
import android.slc.appdb.sys.entity.CsDictData
import android.slc.appdb.sys.service.CsDictDataMapper
import android.slc.box.db.service.DbEntityMapper
import org.apache.commons.lang3.StringUtils

open class DictDataPageVmSub : BaseListPageVmSubByFx<CsDictData>() {
    protected val csDictDataMapper = DbEntityMaster.getService(CsDictDataMapper::class.java)
    lateinit var dictType: String

    override fun onLoadMore() {
        val pageMode = csDictDataMapper.selectByPage(
            loadMoreDataFormatByFx.offset,
            loadMoreDataFormatByFx.size, object : DbEntityMapper.OnSelectConditionListener<CsDictData> {
                override fun onQueryCondition(targetData: CsDictData, queryCondition: CsDictData?): Boolean {
                    return StringUtils.equals(targetData.dictType, dictType)
                }
            }
        )
        createSlcObserver(loadMoreDataFormatByFx.offset).onNext(SlcEntity.getSlcEntityByData(pageMode))
    }

    fun onSearch() {
        firstRefresh()
    }

    /**
     * 重置搜索
     */
    fun onResetSearch() {
    }

    fun onDelete(csDictData: CsDictData) {
        DbEntityMaster.getService(CsDictDataMapper::class.java).remove(csDictData)
        firstRefresh()
    }
}